package com.wanshi.servlet;

import com.alibaba.fastjson.JSON;
import com.wanshi.dao.AreaDao;
import com.wanshi.entity.Province;
import com.wanshi.entity.Shi;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/shi")
public class ShiServlet extends HttpServlet {

    private AreaDao areaDao = new AreaDao();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8");
        String id = request.getParameter("id");


        List<Shi> shis = null;
        try {
            shis = areaDao.getShis(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        response.getWriter().write(JSON.toJSONString(shis));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}

